
var hyischoiced=[];//已经选择的行业document.body.clientWidth
var xqischoiced=[];//已经选择的兴趣
var question = {};
question.score =0;//分数
var ua = navigator.userAgent.toLowerCase();
var isSingle=false;
var singleCallPerson=[];

$(".queskind").html("经验");
$("#sendinfop").html("正在上传经验，请耐心等待..");
document.querySelector(".page_title.unified").innerHTML="编辑修改";
document.querySelector(".navigation_button.sendquesbtn").innerHTML="完成";

var geturl=getdetialurl;//默认为经验接口
question.qtype=3;//2问题3经验
var canEdit=true;//是否可以编辑 防止返回
if(/changeQue=que/.test(location.href)){
    geturl=getquedetialurl;
    question.qtype=2;
    $("#queshow").css("display","block");
    $("#gaojibtn").css("display","none");
}
if($.cookie("changeQue")=="que"){
    geturl=getquedetialurl;
    question.qtype=2;
    $("#queshow").css("display","block");
    $("#gaojibtn").css("display","none");
}
question.isstrangersee = 1;//陌生人是否可见  0否1是
question.ishidename = 0;//是否匿名发布  0否1是
question.iswhocansee = 0;//是否是部分可见 0否1是 和 isforbidwhosee互斥
question.isforbidwhosee = 0;//是否是不给谁看  0否1是 和 iswhocansee互斥
var persons = [];  //招唤的人
var labeldata;//保存标签组
var woseetype="";//用来判断当前标签组是部分可见 还是提醒谁看
//页面按钮控件
var imgbtn=document.querySelector(".modifier.image");//主页面图片按钮
var choiceimgplace=document.getElementsByClassName("choiceimgplace")[0];
var imgokbtn=document.querySelector(".imgokbtn");//图片页面确定按钮
var imgchoicefriend=document.getElementById("sd-imgchoicefriend");//图片选择好友区域
var hidename=document.getElementById("hidename");//陌生人不可见
//问题相关按钮控件
var callfriend=$("#callfriend")[0];//提醒谁看

//主页面添加图片-----------------------------------------
var urlfrom=location.href;
//展示大图片------------------------------------------------
var winscrolltop;
var imghash={};//保存服务器返回的图片地址 “images.localId[i]”：imgurl
var delimgid="";//要删除的图片的Id
//展示大图
function showbigimg(e){
    winscrolltop=$(window).scrollTop();
    $("#page_wrapper").css("display","none");
    $("#showimg").attr("src", imgurl+e.dataset.imgurl);//大图片的地址 和 Id 相同
    $("#digimgplace").css("display","block");
    var bigheight=$("#digimgplace").height();
    var imgheight=$("#showimg").height();
    if(bigheight>imgheight){
        //$("#showimg").css("marginTop",(bigheight-imgheight)/2);
    }
    delimgid=e.dataset.img;//地址 和 Id 相同
}
//展示加载图片
function showloadimg(e){
    $(e).fadeIn();
}
//删除大图
$("#delthisimgbtn").click(function(e){
    imghash[delimgid]="";//清除对应ID 保存的服务器图片地址
    //页面中删掉图片
    var imgbox=document.getElementsByClassName("mainshowimgbox");

    for(var i= 0,r=imgbox.length;i<r;i++){

        if(imgbox[i].dataset.img==delimgid){
            $(".mainshowimgbox")[i].remove();
            break;
        }
    }

    $(".modifier.image").css("display","inlineBlock");
    $("#page_wrapper").css("display","block");
    $("#digimgplace").css("display","none");
    $("#showimg").attr("src","");
});
//关闭地图区域
$("#digimgplace").click(function(e){
    if(e.id!="delthisimgbtn"){
        $("#page_wrapper").css("display","block");
        $("#digimgplace").css("display","none");
        if(winscrolltop>0){
            $(window).scrollTop(winscrolltop);
        }
    }
});
var eid=location.href.match(/eid=[0-9]+/)[0].split("=")[1];
//个人账户
var maxscore=1;
$.ajax({
    type:"get",
    url:"https://www.pulu.com/webapi/api/PuluUser/GetUserScores?userId="+id,
    datatype:"json",
    success:function(data){
        maxscore=parseInt(data.Data.score/100);
    }
});
//监听价格输入
$("#price").on('input propertychange',function(){
    if(!/^[0-9]+$/.test($("#price").val())){
        $("#price").val("");
    }
    if($("#price").val().length>1){
        $("#price").val($("#price").val().replace(/^[0]/,""));
    }
    if(parseInt($("#price").val())>maxscore){
        $("#price").val(maxscore);
    }
});
//获取经验==========================================
$().ready(function(){
    question.id=eid;//2问题3经验
    $.ajax({
        type:"get",
        url:geturl+eid,
        datatype: "json",
        success:function(data){
            if(question.qtype==2&&!data.Data.canEdit){
                canEdit=false;
            }
            //单身资源显示召唤人
            if(data.Data.qtype==4){
                if(data.Data.IntroduceUsers&&data.Data.IntroduceUsers.length>0){
                    singleCallPerson=[data.Data.IntroduceUsers[0].userId];
                    var callerRealName="";
                    if(data.Data.IntroduceUsers[0].realName){callerRealName=" ("+data.Data.IntroduceUsers[0].realName+")"}
                    $("#callfriendwords2").html("<span>"+data.Data.IntroduceUsers[0].nick+callerRealName+"</span>")
                }
                isSingle=true;
            }
            //内容
            //问题转的经验 要添加标题内容
            if(question.qtype==3&&data.Data.isconvert===1){
                $("#contentword").html(data.Data.title+data.Data.content);
            }else{
                $("#contentword").html(data.Data.content);
            }
            //单身 电影 工作 住房
            if(data.Data.qtype!=2&&data.Data.qtype!=3){
                question.qtype=data.Data.qtype;
                if(data.Data.qtype==4||data.Data.qtype==5){$("#locationbox").css("display","none")}
            }
            //获取的问题详情 没有qtype类型
            if(!data.Data.qtype&&$.cookie("changeQue")=="que"){
                question.qtype=2;
            }
            //图片
            if(data.Data.imgList&&data.Data.imgList.length>0){
                for(var i=0;i<data.Data.imgList.length;i++){
                    imghash[data.Data.imgList[i].imgPath]=data.Data.imgList[i].imgPath;
                    $("<div class='mainshowimgbox' style='height:21vw;width:21vw;overflow:hidden;' onclick='showbigimg(this)' data-imgurl='"+data.Data.imgList[i].imgPath+"' data-img='"+data.Data.imgList[i].imgPath+"'><img src='"+imgurl+data.Data.imgList[i].imgPath+"'></div>").insertBefore("#questionbody .modifier.image");
                }
            }
            //关键词
            $("#keywordinput").val(data.Data.keyWords);
            //金额
            if(/changeQue=que/.test(location.href)||$.cookie("changeQue")=="que"){
                //原0.0删除 数值/100
                //document.getElementById("price").value=(data.Data.score)/100;
                document.getElementById("price").value=0;
                $("#price").next("span").html("(原悬赏金额:"+(data.Data.score)/100+"元)");
            }else{
                document.getElementById("price").value=data.Data.score;
            }
            //匿名
            if(data.Data.isHideName ===1){
                question.ishidename = 1;
                $("#hidename div.changephotobox img").attr("src","img/hook01.png")
            }else if(data.Data.isHideName ===0){
                question.ishidename =0;
                $("#hidename div.changephotobox img").attr("src","img/hook-no.png")
            }
            if(data.Data.location){
                $(".myctywords").html(data.Data.location);
            }
            question.longitude=data.Data.longitude;
            question.latitude=data.Data.latitude;
        }
    });
    //加载好友列表
    $.ajax({
        datatype:"json",
        type:"get",
        url:friendlisturl+id,
        success:function(d){
            if(d.Data.length>0){
                //排序
                friendarr= (d.Data).sort(compare);
                hasharr={};//判断字母是否存在
                for(var i=0;i<friendarr.length;i++){
                    if(friendarr[i].friendnick){
                        friendarr[this.index]=i;
                        //如果昵称开头为汉字或英文字母
                        var key=Pinyin.getCamelChars(friendarr[i].friendnick[0]);
                        var headimg="<img src='img/af8.png' class='topic_photo_img'/>"
                        if(friendarr[i].headimg){
                            headimg="<img src='http://42.62.66.198:8003/"+friendarr[i].headimg+"' class='topic_photo_img'/>";
                        }
                        if(key.match(/[a-z|A-Z]/)){
                            key=key.toLowerCase();

                            if(!hasharr[Pinyin.getCamelChars(friendarr[i].friendnick[0])]){
                                hasharr[Pinyin.getCamelChars(friendarr[i].friendnick[0])]=i;
                            }
                            var realname="";
                            if(friendarr[i].realName){realname=" ("+friendarr[i].realName+")";}
                            $("#maina").append("<div class='section_header section_header_gray "+key+"' data-num='"+i+"' style='display:none'> <span class='"+key+"'>"+key+"</span> </div><div class='friends' id='"+friendarr[i].friendId+"'> <input type='checkbox' class='addchatpeoplebtn'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].friendId+"'>"+headimg+"</a> </div> <div class='innerplace tc_text'>"+friendarr[i].friendnick+realname+"</div> </div>");
                            $("#aa").append("<div class='section_header section_header_gray "+key+"' data-num='"+i+"' style='display:none'> <span class='"+key+"'>"+key+"</span> </div><div class='friends' id='"+friendarr[i].friendId+"'> <input type='checkbox' class='addchatpeoplebtn' data-fid='"+friendarr[i].friendId+"'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].friendId+"'>"+headimg+"</a> </div> <div class='innerplace tc_text'>"+friendarr[i].friendnick+realname+"</div> </div>");
                        }else{
                            $("#mainjinghao").css("display","block");
                            var realname="";
                            if(friendarr[i].realName){realname=" ("+friendarr[i].realName+")";}
                            $("#mainjinghao").append("<div class='friends' id='"+friendarr[i].friendId+"'> <input type='checkbox' class='addchatpeoplebtn'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].friendId+"'>"+headimg+"</a> </div> <div class='innerplace tc_text'>"+friendarr[i].friendnick+realname+"</div> </div>");
                            $("#jinghao").css("display","block");
                            $("#jinghao").append("<div class='friends' id='"+friendarr[i].friendId+"'> <input type='checkbox' class='addchatpeoplebtn' data-fid='"+friendarr[i].friendId+"'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].friendId+"'>"+headimg+"</a> </div> <div class='innerplace tc_text'>"+friendarr[i].friendnick+realname+"</div> </div>");
                        };
                    }
                }
                for(var key in hasharr){
                    key=key.toLowerCase();
                    $("#sd-imgchoicefriend .section_header.section_header_gray."+key).eq(0).css("display","block");
                    $("#somesee .section_header.section_header_gray."+key).eq(0).css("display","block");
                    $("#imgchoicefriend .section_header.section_header_gray."+key).eq(0).css("display","block");
                    $("#somesee .section_header.section_header_gray."+key).eq(0).css("display","block");
                };
            }
        }
    });
});

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////主页面操作////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var bodyplace=document.getElementsByClassName("bodyplace")[0];//主页面
var gaojilist=document.getElementsByClassName("gaojilist")[0];//高级页面
var inputbox1=document.querySelector("#inputbox1 div");//主页面确定按钮
//点击后退
$("#maingobackbtn").click(function(){
    history.go(-1);
});
//        输入框
var agt = navigator.userAgent.toLowerCase();
var is_op = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_op;
function ResizeTextarea(a,row){
    if(!a){return}
    if(!row)
        row=5;
    var b=a.value.split("\n");
    var c=is_ie?1:0;
    c+=b.length;
    var d=a.cols;
    if(d<=20){d=40}
    for(var e=0;e<b.length;e++){
        if(b[e].length>=d){
            c+=Math.ceil(b[e].length/d)
        }
    }
    c=Math.max(c,row);
    if(c!=a.rows){
        a.rows=c;
    }
}
//        弹出设置价格
var sendquesbtn=document.getElementsByClassName("sendquesbtn")[0];//提交问题按钮
var tishiwords=document.getElementById("tishiwords");
var modalbg=document.getElementsByClassName("modal_bg")[0];
var modal=document.getElementsByClassName("action_menu_container")[0];
var cancel=document.getElementsByClassName("cancel");
var timer;
var keywordtitle="";//关键词生成的标题

//选择推荐城市-------------------------------------------
function getlocationhash(e){
    $("#page_wrapper").css("display","block");
    //------------------------------------------
    $("#firstchoice .name").html(lacationhash[e.id].name);
    $("#firstchoice .dizhi").html(lacationhash[e.id].address);
    $("#firstchoice img").css("display","block");
    $("#firstchoice").css("display","block");
    //------------------------------------------
    $(".myctywords").html(lacationhash[e.id].name);
    $("#firstchoice").css("display","block");
    $("#firstchoice .name").html(lacationhash[e.id].name);
    $("#firstchoice .dizhi").html(lacationhash[e.id].address);
    $("#showmap").css("display","none");//页面
    $("#firstchoice img").css("display","block");
    $("#nolocation img").css("display","none");//钩
    $("#shiname img").css("display","none");
    //添加地址
    if(e.dataset.lng){
        question.longitude= e.dataset.lng;
        question.latitude=e.dataset.lat;
    }
}
var lacationhash={};//保存所有推荐定位的hash
var choicel=[];//已经选择的定位
//选择“不显示城市”------------------------------------
$("#nolocation").click(function(){
    $(".myctywords").html("");
    $("#firstchoice").css("display","none");
    $("#firstchoice").html("");
    choicel=[];
    $("#showmap").css("display","none");//页面
    $("#nolocation img").css("display","block");
    $("#firstchoice img").css("display","none");
    $("#shiname img").css("display","none");
});
//选择省份----------------------------------------------
var shengshi;//市
$("#shiname").click(function(e){
    $("#firstchoice").css("display","none");
    $(".myctywords").html(shengshi);
    choicel=null;
    $("#showmap").css("display","none");//页面
    $("#nolocation img").css("display","none");//钩
    $("#firstchoice img").css("display","none");
    $("#shiname img").css("display","block");
});
//选地址返回-------------------------------------------
$("#mapgoback").click(function(){
    $("#page_wrapper").css("display","block");
    $("#showmap").css("display","none");//页面
});
//搜索城市----------------------------------------------
var pagenum=1;
function searchcity(pagenum){
    if($("#locationsearch input")[0].value){
        var searchword=$("#locationsearch input")[0].value;
        $("#nosearch").css("display","block");
        var map = new AMap.Map("mapplace", {
            resizeEnable: true
        });
        AMap.service(["AMap.PlaceSearch"], function() {
            var placeSearch = new AMap.PlaceSearch({ //构造地点查询类
                pageSize: 20,
                pageIndex: pagenum,
                city: shengshi, //城市
                map: map
            });
            //关键字查询
            placeSearch.search(searchword,function(status, result){
                var data=result.poiList.pois;
                $(data).each(function(){
                    $("#searclocation").append("<div id="+$(this)[0].id+" onclick='getlocationhash(this)' data-lat='"+$(this)[0].location.lat+"' data-lng='"+$(this)[0].location.lng+"'>"+$(this)[0].name+"<div class='dizhi'>"+$(this)[0].address+"</div></div>");
                    if(!lacationhash[$(this)[0].id]){
                        lacationhash[$(this)[0].id]={"name":$(this)[0].name,"address":$(this)[0].address,"location":$(this)[0].location}
                    }
                });
                $("#locationlistplace").css("display","none");
                $("#otherlist").css("display","none");
                $("#searclocation").css("display","block");
            });
        });
    }
}
//取消搜索----------------------------------------------
$("#nosearch").click(function(){
    $("#searclocation div").remove();
    $("#nosearch").css("display","none");
    $("#locationlistplace").css("display","block");
    $("#otherlist").css("display","block");
    $("#searclocation").css("display","none");
});
//------------------------------------------------------
var pageindex=1;
var nowlocation;//当前位置
window.onload=function(){

//定位 城市-------------------------------------------------
    //周边推荐--------------------
    function otherlocal(position,shiname,pageindex){
        var map = new AMap.Map("mapplace", {
            resizeEnable: true
        });
        AMap.service(["AMap.PlaceSearch"], function() {
            var placeSearch = new AMap.PlaceSearch({ //构造地点查询类
                pageSize: 20,

                pageIndex:pageindex,
                city: shiname, //城市
                map: map
                //panel: "otherlist"
            });
            var cpoint = position; //中心点坐标
            placeSearch.searchNearBy('', cpoint, 200, function(status, result) {
                var data=result.poiList.pois;
                $(data).each(function(){
                    $("#otherlist").append("<div id="+$(this)[0].id+" onclick='getlocationhash(this)' data-lat='"+$(this)[0].location.lat+"' data-lng='"+$(this)[0].location.lng+"'>"+$(this)[0].name+"<div class='dizhi'>"+$(this)[0].address+"</div></div>");
                    if(!lacationhash[$(this)[0].id]){
                        lacationhash[$(this)[0].id]={"name":$(this)[0].name,"address":$(this)[0].address,"location":$(this)[0].location}
                    }
                    //选择周边推荐----------------
                });

            });
        });
    }
    $("#location").click(function(){
        //高德地图--------------------------------------------------
        var map, geolocation;
//加载地图，调用浏览器定位服务
        map = new AMap.Map('mapplace', {
            resizeEnable: true
        });
        map.plugin('AMap.Geolocation', function() {
            geolocation = new AMap.Geolocation({
                enableHighAccuracy: true,//是否使用高精度定位，默认:true
                noIpLocate:0,
                GeoLocationFirst:false,//默认为false，设置为true的时候可以调整PC端为优先使用浏览器定位，失败后使用IP定位
                convert: true,         //自动偏移坐标，偏移后的坐标为高德坐标，默认：true
                timeout: 100000,          //超过100秒后停止定位，默认：无穷大
                buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
                zoomToAccuracy: true,      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
                buttonPosition:'RB'
            });
            map.addControl(geolocation);
            geolocation.getCurrentPosition();
            AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
            AMap.event.addListener(geolocation, 'error', onError);      //返回定位出错信息
        });
//解析定位结果
        function onComplete(data) {
            var shiname=data.formattedAddress.split("省")[1].split("市")[0]+"市";
            shengshi=shiname;
            nowlocation=data.position;
            $("#shiname div").html(shiname);
            otherlocal(data.position,shiname,pageindex);
        }
//解析定位错误信息
        function onError(data) {

        }
        $("#locationlistplace").css("display","block");//搜索影响
        $("#page_wrapper").css("display","none");//搜索影响
        $("#otherlist").css("display","block");
        $("#showmap").css("display","block");//展开页面
    });
    $("#showmap").scroll(function(){
        var mainheight=$(".home_feed").height();
        var windowheight=$(window).height();
        var chajuli=$("#showmap").offset().top - $(window).scrollTop();
        var cz=windowheight-mainheight+5;
        if(chajuli<cz){
            if($("#searclocation").css("display")==="none"){
                pageindex++;
                otherlocal(nowlocation,shengshi,pageindex);
            }
            else{
                pagenum++;
                searchcity(pagenum);
            }
        }
    });
//匿名发布--------------------------------------------------
    hidename.onclick=function(){
        if(question.ishidename ===0){
            question.ishidename = 1;
            $("#hidename div.changephotobox img").attr("src","img/hook01.png")
        }else if(question.ishidename ===1){
            question.ishidename =0;
            $("#hidename div.changephotobox img").attr("src","img/hook-no.png")
        }
    };

//金额加减按钮操作
    //金额加减按钮操作
    $("#leftjianbtn").click(function(){
        var num=$("#price").val();
        num=parseFloat(num);
        if(!num||num<=1){
            $("#price").val(1);
            $("#leftjianbtn").css("backgroundImage","url('img/reduce_light.png')");
            $("#rightjiabtn").css("backgroundImage","url('img/add_deep.png')")
        }else{
            if(num===5){
                $("#price").val(1);
                $("#leftjianbtn").css("backgroundImage","url('img/reduce_light.png')");
                $("#rightjiabtn").css("backgroundImage","url('img/add_deep.png')")
            }else if(num>=9){
                $("#price").val(5);
                $("#rightjiabtn").css("backgroundImage","url('img/add_deep.png')")
            }else{
                --num;
                $("#price").val(num);
                $("#leftjianbtn").css("backgroundImage","url('img/reduce_deep.png')");
                $("#rightjiabtn").css("backgroundImage","url('img/add_deep.png')")
            }
        }
    });
    $("#rightjiabtn").click(function(){
        var num=$("#price").val();
        num=parseFloat(num);
        if(num>=9){
            $("#price").val("9");
            num=9;
            $("#rightjiabtn").css("backgroundImage","url('img/add_light.png')");
            $("#leftjianbtn").css("backgroundImage","url('img/reduce_deep.png')")
        }else{
            if(num===1||!num){
                $("#price").val("5");
                $("#leftjianbtn").css("backgroundImage","url('img/reduce_deep.png')")
            }else if(num===5){
                $("#price").val("9");
                $("#leftjianbtn").css("backgroundImage","url('img/reduce_deep.png')");
                $("#rightjiabtn").css("backgroundImage","url('img/add_light.png')")
            }else{
                ++num;
                $("#price").val(num);
                $("#leftjianbtn").css("backgroundImage","url('img/reduce_deep.png')");
                $("#rightjiabtn").css("backgroundImage","url('img/add_deep.png')")
            }
        }
    });
};

//监听输入框
$("#csearchinput1").bind('input propertychange',function(){
    if(!$("#csearchinput1").val()){
        $("#aa").css("display","block");
        $("#a1").css("display","none");
    }
});
//取消发布
$("#donotsendbtn").click(function(){
    $(".modal_bg.modal_bg2").css("display","none");
    $(".action_menu_container2").css("display","none");
})
//搜索城市--------------------------------------------------
$("#locationsearchbtn").click(function(){
    //城市搜索
    $("#searclocation div").remove();
    searchcity(pagenum);
});
//键盘回车
document.onkeydown=function(event){
    var e = event || window.event || arguments.callee.caller.arguments[0];
    if(e && e.keyCode==13){
        //城市搜索
        $("#searclocation div").remove();
        searchcity(pagenum);
    }
};
$("#gaojibtn").click(function(){
    if($("#hidenamebox").css("display")=="block"){
        //选好友
        $("#callfriend2").css("display","none");
        //匿名发布
        $("#hidenamebox").css("display","none");
        //定位
        $("#locationbox").css("display","none");
        //箭头
        $("#gaojiimg").attr("src","img/darr01.png");
    }else{
        //选好友
        if(isSingle){
            $("#callfriend2").css("display","block");
        }
        //匿名发布
        $("#hidenamebox").css("display","block");
        //定位
        $("#locationbox").css("display","block");
        //箭头
        $("#gaojiimg").attr("src","img/uarr01.png");
    }
});
//单身资源选择好友
callfriend2.onclick=function(){

    //控制选择框状态
    $("#maina input").prop("checked",false);
    if(singleCallPerson.length>0){
        $(singleCallPerson).each(function(i,e){
            $(".friends#"+e+" input").prop("checked",true);
        })
    }
    bodyplace.style.display="none";
    imgchoicefriend.style.display="block";//与图片共用一个好友列表
    $(window).scrollTop(0);
    //sendfriend=1;
    //callfrienfname=[];
};
//监听选择框 单身只能选一个
$("#maina").bind("click","input",function(i){
    console.log("执行");
    if($(i.target).prop("type")=="checkbox"){
        if($(i.target).prop("checked")){
            singleCallPerson=[$(i.target).parent(".friends").attr("id")];
            console.log(singleCallPerson);
            imgchoicefriend.style.display="none";
            bodyplace.style.display="block";
            $("#callfriendwords2").html("<span>"+$(i.target).parent(".friends").children(".tc_text").html()+"</span>")
        }else if(!$(i.target).prop("checked")){
            console.log("清除");
            singleCallPerson=[];
            $("#callfriendwords2").html("");
        }
    }
});
//
$("#friendlistgoback").click(function(){
    imgchoicefriend.style.display="none";
    bodyplace.style.display="block";
});
// 提交所有信息
sendquesbtn.onclick=function(){
    if(canEdit){
        var imgs =new Array();//图片列表-------用于向服务器传递参数
        if(question.qtype!=2&&($("#contentword").val().trim().length<10)){
            alert("字数有点少，再加点吧，至少10字哦");
        }else if(question.qtype==2&&$("#contentword").val().trim().length==0){
            alert("内容不能为空");
        }else if(question.qtype==4&&!$(".mainshowimgbox")[0]){
            alert("至少上传一张照片");
        }else{
            //经验要有关键词
            var keyword=document.getElementById("keywordinput").value;
            //关键词
            if(document.getElementById("keywordinput").value&&!document.getElementById("keywordinput").value.match(/^\s+$/g)){
                //最后操作获取其他参数 发送请求====================================================================
                //图片
                if(document.getElementsByClassName("mainshowimgbox")[0]){
                    console.log("有图片",document.getElementsByClassName("mainshowimgbox"));
                    //从数组中获取图片
                    var imgbox=document.getElementsByClassName("mainshowimgbox");
                    for(var i= 0,len=imgbox.length;i<len;i++){
                        if(question.qtype!=2){
                            var img={};
                            img.plist ="";
                            img.name=imgbox[i].dataset.img;
                            imgs.push(img);
                        }
                        //问题
                        else{
                            if(!/Images\//.test(imgbox[i].dataset.img)){
                                imgs.push("Images/"+imgbox[i].dataset.img+".jpg");
                            }else{
                                imgs.push(imgbox[i].dataset.img);
                            }
                        }
                    }
                }else{
                    console.log("没有图");
                    if(question.qtype!=2){imgs="[]";}
                }
                //问题或经验
                if(question.qtype!=2){
                    //定位
                    if($(".myctywords span")){
                        if($(".myctywords").html()!="所在位置"){
                            question.pululocation = $(".myctywords").html();
                        }
                    }
                    //发送问题的关键字
                    question.keywords=$("#keywordinput").val();
                    //经验的金额
                    if(document.getElementById("price").value){
                        if(document.getElementById("price").value.match(/^[0-9]+$/g)){
                            question.content = document.getElementById("contentword").value;
                            question.questionUserId = id;//发布人的id
                            question.status ="1";
                            question.score=parseFloat(document.getElementById("price").value);//分数
                            $("#sendinfo").css("display","block");
                            console.log(typeof(imgs));
                            console.log(imgs);
                            //可以提交数据
                            $.ajax({
                                type: "post",
                                url: changemysendurl,
                                data: {"imgs":imgs,"atmeuserId": $.cookie("MYID"),"pulu_question": question,"qSeePlist": "","persons1":singleCallPerson},
                                success: function (data) {
                                    if(data.Code=="TRUE"){
                                        $.cookie("reloadPage","reloadPage");
                                        //浏览器 返回未刷新问题
                                        var comf=document.referrer;
                                        if(!/fromuser/.test(location.href)){comf+="#fromuser="+ $.cookie("MYID")}
                                        location.href=comf;
                                    }else{
                                        $("#sendinfo").css("display","none");
                                        alert("关键词未在文中出现");
                                    };
                                },
                                error:function(d){
                                    alert("经验修改失败");
                                }
                            });
                        }
                    }else{
                        alert("经验金额不能为0");
                    }
                }
                else if(question.qtype==2){
                    if(!document.getElementById("price").value){
                        document.getElementById("price").value=0;
                    }
                    var sendque={};
                    sendque.refquestionId=eid;
                    sendque.content=document.getElementById("contentword").value;
                    sendque.keywords=document.getElementById("keywordinput").value;
                    sendque.score=parseFloat(document.getElementById("price").value)*100;
                    sendque.imgs=imgs.join();
                    sendque.quserId=$.cookie("MYID");
                    $.ajax({
                        type: "post",
                        url: "https://www.pulu.com/webapi/api/QuestionUpdate/AddquestionForUpdate",
                        //data: {"imgs":imgs,"keywords":quekeywords,"content": quecontnet,"score":quescro,"refquestionId":refquestionId,"quserId": $.cookie("MYID")},
                        data:sendque,
                        contenttype:"applicatio/json",
                        datatype: "json",
                        success: function (data) {
                            if(data.Code=="TRUE"){
                                alert("您的悬赏修改申请已提交，修改结果请等待系统通知");
                                $.cookie("reloadPage","reloadPage");
                                history.go(-1);
                                //if(ua.match(/MicroMessenger/i)=="micromessenger"){
                                //    location.href="http://www.pulu.com/weixin/questiondetail.html?qid="+eid+"#fromuser="+id;
                                //}else{
                                //    location.href="https://www.pulu.com/weixin/questiondetail.html?qid="+eid+"#fromuser="+id;
                                //}
                            }else{
                                $("#sendinfo").css("display","none");
                            };
                        },
                        error:function(d){
                            alert(d.Data);
                        }
                    });
                }

            }
            else{
                alert("关键词不能为空");
            }
        }
    }
    else{
        alert("悬赏已在审核中，请耐心等候");
        history.go(-1);
        //if(ua.match(/MicroMessenger/i)=="micromessenger"){
        //    location.href="http://www.pulu.com/weixin/questiondetail.html?qid="+eid+"#fromuser="+id;
        //}else{
        //    location.href="https://www.pulu.com/weixin/questiondetail.html?qid="+eid+"#fromuser="+id;
        //}
    }
};